package ca.kooki.codesnippet.core;

import junit.framework.Assert;

import org.junit.Test;

public class SearchInputTest {

  
  @Test
  public void isAll()
  {
    SearchInput input = new SearchInput();
    Assert.assertEquals(true,input.isAll());

    input = new SearchInput(null);
    Assert.assertEquals(true,input.isAll());

    input = new SearchInput("");
    Assert.assertEquals(true,input.isAll());

    input = new SearchInput("/aforward");
    Assert.assertEquals(false,input.isAll());

    input = new SearchInput("blah blah");
    Assert.assertEquals(false,input.isAll());

  }
  
  @Test
  public void Username()
  {
    SearchInput input = new SearchInput();
    Assert.assertEquals(false,input.hasUsername());
    Assert.assertEquals("",input.getUsername());
    
    input = new SearchInput(null);
    Assert.assertEquals(false,input.hasUsername());
    Assert.assertEquals("",input.getUsername());
    
    input = new SearchInput("");
    Assert.assertEquals(false,input.hasUsername());
    Assert.assertEquals("",input.getUsername());

    input = new SearchInput("/aforward");
    Assert.assertEquals(true,input.hasUsername());
    Assert.assertEquals("aforward",input.getUsername());

    input = new SearchInput("blah blah");
    Assert.assertEquals(false,input.hasUsername());
    Assert.assertEquals("",input.getUsername());
  }
  
  @Test
  public void isRelevantToEmpty()
  {
    SearchInput input = new SearchInput();
    Assert.assertEquals(true,input.isRelevantTo(null));
    Assert.assertEquals(true,input.isRelevantTo(""));
  }

  @Test
  public void isRelevantFromPath()
  {
    SearchInput input = new SearchInput("/aforward/k1/k2");

    Assert.assertEquals(true,input.isRelevantTo("k1"));
    Assert.assertEquals(true,input.isRelevantTo("k2"));
    Assert.assertEquals(true,input.isRelevantTo("k1 k2"));
    Assert.assertEquals(true,input.isRelevantTo("k1 k3"));
    Assert.assertEquals(false,input.isRelevantTo("k4 k3"));
    Assert.assertEquals(false,input.isRelevantTo("k"));
  }

  @Test
  public void isRelevantFromPathWithoutAnySearchTerms()
  {
    SearchInput input = new SearchInput("/aforward");

    Assert.assertEquals(true,input.isRelevantTo(""));
    Assert.assertEquals(true,input.isRelevantTo(null));
    Assert.assertEquals(true,input.isRelevantTo("k"));
    Assert.assertEquals(true,input.isRelevantTo("k1 k2"));
  }

  
  @Test
  public void isRelevantFromJustKeywords()
  {
    SearchInput input = new SearchInput("k1 k2");

    Assert.assertEquals(true,input.isRelevantTo("k1"));
    Assert.assertEquals(true,input.isRelevantTo("k2"));
    Assert.assertEquals(true,input.isRelevantTo("k1 k2"));
    Assert.assertEquals(true,input.isRelevantTo("k1 k3"));
    Assert.assertEquals(false,input.isRelevantTo("k4 k3"));
    Assert.assertEquals(false,input.isRelevantTo("k"));
  }
  
  @Test
  public void FromDefault()
  {
    SearchInput input = new SearchInput();
    Assert.assertEquals(User.ANNONYMOUS, input.from());
  }
  
  @Test
  public void getSearchQuery()
  {
    SearchInput input = null;
    
    input = new SearchInput();
    Assert.assertEquals("", input.getSearchQuery());

    input = new SearchInput("blah");
    Assert.assertEquals("blah", input.getSearchQuery());

    
  }

  
}
